package zero.tech.games.phz.event;

import com.alibaba.fastjson.JSONObject;

import zero.tech.core.event.EventListener;
import zero.tech.core.event.EventType;
import zero.tech.games.logic.common.Room;
import zero.tech.games.logic.data.LogicEventType;
import zero.tech.games.phz.data.PhzConfig;
import zero.tech.games.phz.data.PhzGameBase;
import zero.tech.games.phz.data.PhzRoomCache;
import zero.tech.games.phz.data.PhzTimer;

public class RoomCreated implements EventListener{

	@Override
	public EventType netEventType() {
		return LogicEventType.ROOM_CREATED;
	}

	@Override
	public void notifyEvent(Object... objs) {
		Room room = (Room) objs[0];
		PhzTimer phzTimer=new PhzTimer(room.getRoom_id());
		room.setTimer(phzTimer);
		PhzRoomCache phzRoomCache=new PhzRoomCache(room.getRoom_id());
		room.setRoomCache(phzRoomCache);
		PhzConfig phzConfig=JSONObject.parseObject(room.getConfigStr(),PhzConfig.class);
		room.setGameConfig(phzConfig);
		PhzGameBase phzGameBase=new PhzGameBase(room.getRoom_id());
		room.setGameBase(phzGameBase);
	}

	@Override
	public boolean asynchronous() {
		return false;
	}

}
